package org.example.springbook.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.springbook.model.BookInfo;
import org.example.springbook.model.PageRequest;

import java.util.List;

@Mapper
public interface BookMapper {
    @Select("select * from book_info where status!=0")
    List<BookInfo> queryBookList();

    @Insert("insert into book_info(book_name, author, count, price, publish) " +
            "values (#{bookName}, #{author}, #{count}, #{price}, #{publish})")
    Integer insertBook(BookInfo bookInfo);

    @Select("select count(*) from book_info where status!=0")
    Integer count();

    @Select("select * from book_info where status!=0 order by id desc limit #{offset}, #{pageSize}")
    List<BookInfo> queryBookListByPage(PageRequest pageRequest);

    @Select("select * from book_info where id=#{bookId}")
    BookInfo queryBookById(Integer bookId);

    Integer updateBook(BookInfo book);

    Integer batchDelete(List<Integer> ids);
}
